package app.oa.comm;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class EntityMap {

	private Object obj;
	private Map<String, Object> map = new HashMap<>(0);
	
	public EntityMap(Object obj) {
		this.obj = obj;
	}
	
	public EntityMap addParam(String propertyName) {
		String getterName = "get" + propertyName.substring(0, 1).toUpperCase()
				+ propertyName.substring(1);
		Method method;
		try {
			method = obj.getClass().getMethod(getterName);
			map.put(propertyName, method.invoke(obj));
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		return this;
	}
	
	public Map<String, Object> toMap(){
		return map;
	}
}
